package com.happy_lab_management.util;

import java.lang.reflect.Field;

public class CopyFieldUtil {
    public static <T> void copyCommonAttributes(T source,T target) throws IllegalAccessException {
        Class<?> classA = source.getClass();
        Field[] fieldsA = classA.getDeclaredFields();
        Class<?> classB = target.getClass();
        Field[] fieldsB = classB.getDeclaredFields();

        for (Field fieldA : fieldsA) {
            for (Field fieldB : fieldsB) {
                if (fieldA.getName().equals(fieldB.getName())) {
                    fieldB.setAccessible(true);
                    fieldA.setAccessible(true);
                    fieldB.set(target, fieldA.get(source));
                }
            }
        }
    }
}
